<?                           


                                                                                                                                                                                                  
    function decode_message_content_output($part,$limit=0,$font=NULL,$msgid=NULL,$groupid=NULL,$errors=NULL) {                                                                                                                                                                                               
                                                                                                                                                                                                   
        global $breadcrumb;                                                                                                                                                                                               
        global $breaddata;                                                                                                                                                                                               
        global $preview_temp;                                                                                                                                                                                               
                                                                                                                                                                                                        
        $breadcrumb         .= "Ua";                                                                                                                                                                                               
        $encoding            = $part["header"]["content-transfer-encoding"];                                                                                                                                                                                               
        $filename            = $part["filename"];                                                                                                                                                                  
        $data                = $part["body"];                                                                                                                                                                                               
        $image_p             = false;                                                                                                                                                                                                
        $raw_cache_file      = cache_file ($msgid, "raw",$groupid);                                                                                                                                                                                               
        $image_cache_file    = cache_file ($msgid, $limit,$groupid);                                                                                                                                                                                               
        $error_cache_file    = "data/temp/error/_" . $groupid . "_error_" . $msgid . ".txt";                                                                                                                                                                
                                                                                                                                                                                           
        if ( strpos($data, "ybegin") !== false )                                                                                                                                                                                               
        {                                                                                                                                                                                               
            $encoding = "yenc";                                                                                                                                                                                               
        }                                                                                                                                                                                               
                                                                                                                                                                                                       
        if ($msgid!=NULL && file_exists($raw_cache_file))                                                                                                                                                                                               
        { # revived from a prior success                                                                                                                                                                                                    
            $breadcrumb .= "Ub";                                                                                                                                                                                
            $im = imagecreatefromjpeg($raw_cache_file);                                                                                                                                                          
                                                                                                                                                                                       
        }                                                                                                                                                                                               
        else if ($im = @imagecreatefromjpeg($error_cache_file))                                                                                                                                                                                              
        { # revived from a prior error                                                                                                                                                                                    
             $breadcrumb .= "[$error_cache_file]";                                                                                                                                                                                               
        }                                                                                                                                                                                               
        else                                                                                                                                                                                               
        { # decode incoming data                                                                                                                                                                                              
            if (stristr($encoding, "quoted-printable"))      
            {                                                                                                                                                                                               
                $data = quoted_printable_decode($part["body"]);                                                                                                                                                                                               
                $breadcrumb .= "Uc";                                                                                                                                                                                               
            }      
            else if (stristr($encoding, "base64"))      
            {                                                                                                                                                                                               
                $data = base64_decode($part["body"]);                                                                                                                                                                                               
                $breadcrumb .= "Ud";                                                                                                                                                                                               
            }       
            else if (stristr($encoding, "uuencode"))      
            {                                                                                                                                                                                               
                $data = uudecode($part["body"]);                                                                                                                                                                                                
                $breadcrumb .= "Ue";                                                                                                                                                                                               
            }       
            else if ($encoding=="yenc")      
            {                                                                                                                                                                                                 
                $enc  = new yenc();                                                                                                                                                                                                
                $data =  $enc->decode($part["body"]);                                                                                                                                                                                                  
                $breadcrumb .= "Uf";                                                                                                                                                                                                
            }       
            else      
            { // No need to decode                                                                                                                                                                                               
                $breadcrumb .= "Ug";                                                                                                                                                                                               
                $data   = $part["body"];                                                                                                                                                                                               
                $limit  = $limit>0?$limit:320;                                                                                                                                                                                               
                $im     = imagecreatetruecolor($limit, $limit);                                                                                                                                                                                                                  
                $trans = imagecolorallocate ($im, 255, 255, 255);                                                                                                                                                                                               
                imagefill ($im, 0, 0, $trans);                                                  
                if (isset($_GET["text"]))                                             
                {                                             
                    header ("Content-Type: text/plain");                                                 
                    header ("Content-Disposition: attachment; filename='msgid_".$msgid.".txt'");                                                                                                                                                                                           
                    echo $data;                                                                                                                                                                                             
                }                                             
                else                                             
                {                                             
                    draw_gd_image ($im, $image_cache_file, 100, $font, $data, 2, 4);                                             
                }                                             
                return true;                                                                                                                                                                                               
            }                                                                                                                                                                                                  
            $breadcrumb .= "Uh";                                                                                                                                                                                               
            $im = @imagecreatefromstring($data); # Load decoded string into GD image object                                                                                                                                                                                                 
        }                                                                                                                                                                                                 
                                                                                                                                                                                                       
                                                                                                                                                                                
                                                                                                                                                                                                       
        if ($limit>0)                                                                                                                                                                                               
        {                                                                                                                                                                                                   
            if ($msgid!=NULL && file_exists($image_cache_file))                                                                                                                                                                                               
            {                                                                                                                                                                                               
                $breadcrumb .= "Ui";                                                                                                                                                                                               
                $image_p = imagecreatefromjpeg($image_cache_file);                                                                                                                                                  
                draw_gd_image ($image_p, NULL, 100, $font, $filename);                                                                                                                                                                                                 
                return true;                                                                                                                                                                                               
            }                                                                                                                                                                                               
            else                                                                                                                                                                                               
            {                                                                                                                                                                                                
                if ($im)                                                                                                                                                                                                
                { # create fresh RESIZED (THUMBNAIL) image          
                    # -------------------------------------------------------------------------                                                                                                                                                                                    
                    $sx=imagesx ($im);                                                                                                                                                                                               
                    $sy=imagesy ($im);                                                                                                                                                                                               
                    $sr=$sx/$sy;                                                                                                                                                                                               
                    if ($sr>1.4&&$sr<2&&array_search($groupid,$preview_temp)!==false)                                                                                                                                                                                               
                    { # HACK: saves some images for the home splash page                                                                                                                                                                                               
                        imagejpeg($im, "./data/temp/home/" . $groupid .".jpg.".$msgid, 100);                                                                                                                                                                                               
                    }                                                                                                                                                                                               
                    if ($sr>0.59&&$sr<0.68&&array_search($groupid,$preview_temp)!==false)                                                                                                                                                                                               
                    { # HACK: saves some images for the home splash page                                                                                                                                                                                               
                        if (!is_dir("./data/temp/tall"))                                                                                                                                                                                               
                        {                                                                                                                                                                                               
                              mkdir ("./data/temp/tall");                                                                                                                                                                                               
                        }                                                                                                                                                                                               
                        imagejpeg($im, "./data/temp/tall/" . $groupid .".jpg.".$msgid, 100);                                                                                                                                                                                               
                    }                                                                                                                                                                                               
                    # -------------------------------------------------------------------------                                                                                                                                                                                    
                                                                                                                                                                                                       
                    $breadcrumb .= "Ujb";                                                                                                                                                                                               
                    output_image($im, $limit, $font, $msgid, $filename, $image_cache_file);                                                                                                                                                                                                
                    $breadcrumb .= "Uj";                                                                                                                                                                                               
                    draw_gd_image ($im, $raw_cache_file);                                                                                                                                                              
                    return true;                                                                                                                                                                                           
                }                                                                                                                                                                                               
                else                                                                                                                                                                                               
                {                                                                                                                                                                                               
                    $breadcrumb .= "[The image parser was unable to create a picture from the data that was received]"; # forces an error                                                                                                                                                                                                
                    echo $data;                                                                                                                                                                                                          
                }                                                                                                                                                                                               
            }                                                                                                                                                                                                
        }                                                                                                                                                                                               
        else if ($im)                                                                                                                                                                                                
        { # create fresh FULLSIZE image                                                                                                                                                                                               
            $breadcrumb .= "Ukb";                                                                                                                                                                                               
            draw_gd_image ($im, NULL, 100, NULL, $filename);                                                                                                                                                                                                  
            $breadcrumb .= "Uk";                                                                                                                                                                                               
            draw_gd_image ($im, $raw_cache_file);                                                                                                                                                                  
            return true;                                                                                                                                                                                    
        }                                                                                                                                                                                               
        else                                                                                                                                                                                                
        {                                                                                                                                                                                                  
            echo $data;                                                                                                                                                         
                                                                                                                                                                                                       
        }                                                                                                                                                             
        WriteToFile ($error_cache_file, $data);                                                                                                                                                   
        foreach ($errors as $pointer)                                                                                                                                                                 
        {                                                                                                                                                                 
           $error_point_file = "data/temp/error/_" . $groupid . "_error_" . $pointer . ".txt_pointer";                                                                                                                                                                   
           WriteToFile ($error_point_file, $msgid);                                                                                                                                                                                                  
        }                                                                                                                                                                                          
                                                                                                                                                                                             
    }                                                                                                                                                                                                       
                                                                                                                                                                                                   
    function imageflip ($im,$opt="FH") {                                                                                                                                                                                               
                                                                                                                                                                                                
        $actual_image_width  = imagesx($im);                                                                                                                                                                                               
        $actual_image_height = imagesy($im);                                                                                                                                                                                                
        $nm=imagecreatetruecolor($actual_image_width,$actual_image_height);                                                                                                                                                                                                
        for($x=0;$x<=$actual_image_width;$x++) {                                                                                                                                                                                               
            for($y=0;$y<=$actual_image_height;$y++) {                                                                                                                                                                                                
                $rgb = imagecolorat($im, $opt=="FH"?(($actual_image_width-1)-$x):$x, $opt=="FH"?$y:(($actual_image_height-1)-$y));                                                                                                                                                                                                  
                imagesetpixel($nm,$x,$y,$rgb);                                                                                                                                                                                                  
            }                                                                                                                                                                                               
        }                                                                                                                                                                                                
        return $nm;                                                                                                                                                                                               
    }        
                                                                                                                                                                                              
    function output_image($im,$limit=0,$font=NULL,$msgid=NULL,$caption="",$saveas=NULL)                                                                                                                                                                                               
    {                                                                                                                                                                                               
         global $breadcrumb;                                                                                                                                                                                               
        $breadcrumb .= "Ul";                                                                                                                                                                                               
        $width      = imagesx($im);                                                                                                                                                                                               
        $height     = imagesy($im);                                                                                                                                                                                                
        $ratio      = $width/$height;                                                                                                                                                                                                            
                                                                                                                                                                                                       
        $adj_x = 2;                                                                                                                                                                                               
        $adj_y = 2;                                                                                                                                                                                               
        if ($width>$height||$font!=NULL)                                                                                                                                                                                                
        {                                                                                                                                                                                                
             $new_width  = $limit;                                                                                                                                                                                                
             $new_height = floor($new_width / $ratio);                                                                                                                                                                            
             #$new_height = $limit;                                                                                                                                                                                                
             #$new_width = floor($new_height * $ratio);                                                                                                                                                                                              
             $adj_x = 2;                                                                                                                                                                                               
             $adj_y = 2;                                                                                                                                                                                               
        }                                                                                                                                                                                                
        else                                                                                                                                                                                                
        {                                                                                                                                                                                                
             $new_height = $limit;                                                                                                                                                                                                
             $new_width = floor($new_height * $ratio);                                                                                                                                                                                                
        }                                                                                                                                                                                                          
        // Resample                                                                                                                                                                                               
        $adj_x = isset($_GET["shadow"]) ? 1 : 0;                                                                                                                                                                                               
        $adj_y = $adj_x;                                                                 
        $dst_x = 0;                                                           
        $dst_y = 0;                                                           
        $src_x = 0;                                                           
        $src_y = 0;                                                           
        $dst_w = $new_width-$adj_x;                                                           
        $dst_h = $new_height-$adj_y;                                                           
        $src_w = $width;                                                           
        $src_h = $height;                                                           
        if (isset($_GET["center"]))                                                            
        {                                                             
            $image_p = imagecreatetruecolor($limit, $limit);                                                           
            $dst_x = ($limit - $new_width) / 2;                                                           
            $dst_y = ($limit - $new_height) / 2;                                                           
        }                                                            
        else                                                            
        {                                                            
            $image_p = imagecreatetruecolor($new_width, $font==NULL?$new_height:$new_width);                                                           
        }                                                              
                                                             
        # imagecopyresampled ( resource dst_image, resource src_image, int dst_x, int dst_y, int src_x, int src_y, int dst_w, int dst_h, int src_w, int src_h )                                                            
                                                                                                                                                                      
                                                                                                                                                                                                          
        $trans = imagecolorallocate ($image_p, 255, 255, 255);                                                                                                                                                                                               
        imagefill ($image_p, 0, 0, $trans);                                                                                                                                                                                               
        imagecolortransparent($image_p, $trans);                                                                                                                                                                                               
                                                                                                                                                                                                         
        $breadcrumb .= "Up";                                                                                                                                                                                               
        $col = imagecolorallocate ($image_p, 200, 200, 200);                                                                                                                                                                                               
        $wht = imagecolorallocate ($image_p, 255, 255, 255);                                                                                                                                                                                                                    
        imagefilledrectangle( $image_p,$dst_x+$adj_x,$dst_y+$adj_x,$dst_x+$new_width,$dst_y+$new_height,$col);                                                             
                                                                                                                                                                                              
        imagecopyresampled($image_p, $im, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);                                                                                                                                         
                                                                           
        if (! isset($_GET["center"]) )                                                            
        {                                                                                                                                                                             
                                                                                                                                          
            $actual_image_width  = imagesx($image_p);                                                                                                                                                                                               
            $actual_image_height = imagesy($image_p);                                                                                                                                                                                                
            $actual_image_offset = $dst_y + ($new_height-1);                                                                                                                                                                                                
            $actual_alpha_offset = 0;                                                                                                                                                                                                
            for($y=$actual_image_offset;$y<=$actual_image_height;$y++)                                                                                                                                  
            {                                                                                                                                                                                               
                                                                                                                                                    
                for($x=0;$x<=$actual_image_width;$x++)                                                                                                                                        
                {                                                                                                                                                                                                
                    $rgb = imagecolorat($image_p, $x, $actual_image_offset);                                                                                                                                                                                                  
                    # imagesetpixel($image_p,$x,$y,$rgb);                                                                                                                                   
                    $tmp=imagecreatetruecolor (1,1);                                                                                                                                                                                          
                    imagesetpixel($tmp,0,0,$rgb);                                                                                                                                    
                    imagecopymerge($image_p,$tmp,$x,$y,0,0,1,1,90-$actual_alpha_offset);                                                                                                                                
                    imagedestroy ($tmp);                                                                                                                                     
                                                                                                                                                                                                                
                }                                                                                                                                    
                $actual_image_offset--;                                                                                                                              
                $actual_alpha_offset += 1;                                                                                                                                
                if ($actual_alpha_offset > 100)                                                                                                                              
                {                                                                                                                              
                    break;                                                                                                                              
                }                                                                                                                                                                                           
            }                                                                                                                                                                                           
        }                                                                                                                                         
                                                                                                                                                                                          
                                                                                                                                                                                 
        if (isset($_GET["pp_b"]))   $image_p=rounded_mask ($image_p,$new_width,$new_height)    ;                                                                                                                                                                          
        if ($image_p)                                                                                                                                                                                               
        {                                                                                                                                                                                                
            draw_gd_image ($image_p, $saveas, 100, $font, $caption);                                                                                                                                                                                                
        }                                                                                                                                                                                               
    }                                                                                                                                                                                                       
                                                                                                                                                                                                   
    function random_image()                                                                                                                                                                                               
    {                                                                                                                                                                                               
        global $breadcrumb;                                                                                                                                                                                               
        $breadcrumb .= "Um";                                                                                                                                                                                               
        $dir = CACHE_PATH . "raw";                                                                                                                                                                                                 
        $arr = array();                                                                                                                                                                                               
        if (is_dir($dir))                                                                                                                                                                                                
        {                                                                                                                                                                                               
           if ($dh = opendir($dir))                                                                                                                                                                                                
           {                                                                                                                                                                                               
               while (($file = readdir($dh)) !== false)                                                                                                                                                                                                
               {                                                                                                                                                                                                
                   if (preg_match ("/(.*)\.jpg/i", $file, $tmp))                                                                                                                                                                                               
                   {                                                                                                                                                                                                  
                       $arr[]= $file;                                                                                                                                                                                                
                   }                                                                                                                                                                                               
               }                                                                                                                                                                                               
               closedir($dh);                                                                                                                                                                                               
           }                                                                                                                                                                                               
        }                                                                                                                                                                                                
        $file=$arr[time()%count($arr)];                                                                                                                                                                                                
        $im = imagecreatefromjpeg($dir."/".$file);                                                                                                                                                                                                 
        return $im;                                                                                                                                                                                               
    }                                                                                                                                                                                               
                                                                                                                                                                                                   
    function draw_gd_image ($im, $saveas=NULL, $quality=100, $font=NULL, $stamp=NULL)                                                                                                                                                                                               
    {                                                                                                                                                                                               
         global $breadcrumb;                                                                                                                                                                                               
         global $breaddata;                                                                                                                                                                                               
        $breadcrumb .= "Un";                                                                                                                                                                                               
        $ok = true;                                                                                                                                                                                               
        if ($im)                                                                                                                                                                                               
        {                                                                                                                                                                                                
            if (isset($saveas))                                                                                                                                                                                               
            {                                                                                                                                                                                                 
                imagejpeg($im, $saveas, $quality);                                                                                                                                                                                               
            }                                                                                                                                                                                                     
            if (is_array($font))                                                                                                                                                                                               
            {                                                                                                                                                                                                
                write_gd_font ($im, $font);                                                                                                                                                                                               
            }                                                                                                                                                                                               
            else                                                                                                                                                                                               
            {                                                                                                                                                                                               
                #$rg = imagecolorallocate($im, 255, 0, 99);                                                                                                                                                                                                 
                #write_gd_string ($im, $breadcrumb,2,28,160,$rg);                                                                                                                                                                                                
            }                                                                                                                                                                                               
            if (isset($stamp))                                                                                                                                                                                               
            {                                                                                                                                                                                                
                $breadcrumb .= "Uo";                                                                                                                                                                                               
                write_gd_string ($im, $stamp);                                                                                                                                                                                                
            }                                                                                                                                                                                                
        }                                                                                                                                                                                               
        else                                                                                                                                                                                               
        {                                                                                                                                                                                                
            $im = imagecreate(320,320);#random_image();                                                                                                                                                                                                
            $wg = imagecolorallocate($im, 255, 255, 255);                                                                                                                                                                                                  
            $gg = imagecolorallocate($im, 155, 155, 155);                                                                                                                                                                                                  
            $bg = imagecolorallocate($im, 255, 0, 66);                                                                                                                                                                                                   
                                                                                                                                                                                                            
            imagettftext($im, 14, 0, 4, 50, $bg , DEFAULT_IMAGE_FONT, "NewsJet");                                                                                                                                                                                                 
            imagettftext($im, 10, 0, 4, 64, $gg , DEFAULT_IMAGE_FONT, "Newsgroup Browser");                                                                                                                                                                                                 
            write_gd_string ($im, $breadcrumb,6,20,imagesx($im)-20,$gg,2);                                                                                                                                                                                               
        }                                                                                                                                                                                               
                                                                                                                                                                                                         
        # write_gd_string ($im, $breadcrumb,6,20,imagesx($im)-20,$gg,2);                                                                                                                                                                                            
                                                                                                                                                                                
        # imageflip ($im);          
		if (isset($saveas))        
		{
            header ("Content-Disposition: attachment; filename='".$saveas."'");    
		}                                                                                                                                                                             
        header ("Content-Type: image/jpeg");                                                                                                                                                  
        # $im=rounded_mask ($im);                                                                                                                                                                                                 
        imagejpeg($im, "", 100);                                                                                                                                                                                               
        #imagegif($im);                                                                                                                                                                                               
        #imagepng($im);                                                                                                                                                                                      
        imagedestroy ($im);                                                                                                                                                                                               
    }                            
                                                                                                                                                                       
    function write_gd_font($im, $font)                                                                                                                                                                                               
    {                                                                                                                                                                                               
        $color   = $font["color"];                                                                                                                                                                                               
        $gray    = imagecolorallocate($im, 255, 255, 255);                                                                                                                                                                                                 
        $color   = imagecolorallocate($im, $color["red"], $color["green"], $color["blue"]);                                                                                                                                                                                                 
        $angle   = $font["angle"] == "" ? 0 : $font["angle"];                                                                                                                                                                                                
        imagettftext($im, $font["size"], $angle, $font["x"]+2, $font["y"]+2, $color , $font["file"], $font["text"]);                                                                                                                                                                                               
        imagettftext($im, $font["size"], $angle, $font["x"], $font["y"], $gray , $font["file"], $font["text"]);                                                                                                                                                                                               
    }                     
                                                                                                                                                                              
    function write_gd_string($im, $string,$error_string_x=2,$error_string_y=2,$limit=NULL,$col=NULL,$size=1)                                                                                                                                                                                               
    {                                                                                                                                                                                               
        $wc      = imagecolorallocate($im, 205, 205, 205);                                                                                                                                                                                                 
        $red     = imagecolorallocate($im, 255, 0, 0);                                                                                                                                                                                                 
        $start_x = $error_string_x;                                                                                                                                                                                               
        if ($col==NULL)                                                                                                                                                                                               
        {       
            $sx=imagesx ($im);                                                              
            $sy=imagesy ($im);                                                              
            $col = imagecolorat($im, time() % $sx, time() % $sy);                                                                                                                                                                                            
            # $col = imagecolorallocate($im, 255, 150, 150);                                                                                                                                                                                                 
        }                                                                                                                                                                                               
        if ($limit==NULL)                                                                                                                                                                                               
        {                                                                                                                                                                                               
            $limit = imagesx ($im)-6;                                                                                                                                                                                               
        }                                                                                                                                                                                               
        $color = $col;                                                                                                                                                                                               
        for ($z=0;$z<strlen($string);$z++)                                                                                                                                                                                                
        {                                                                                                                                                                                               
           $c=substr($string,$z,1);                                                                                                                                                                                                 
           if ($c=="\n"||$c=="\r")                                                                                                                                                                                                
           #if ($c=="\r")                                                                                                                                                                                                
           {                                                                                                                                                                                               
               $error_string_y+= imagefontheight($size);                                                                                                                                                                                               
               $error_string_x=$start_x;                                                                                                                                                                                               
           }                                                                                                                                                                                               
           else                                                                                                                                                                                               
           {                                                                                                                                                                                               
               if ($c=="[")                                                                                                                                                                                               
               {                                                                                                                                                                                               
                  $color=$red;                                                                                                                                                                                               
                  $error_string_y+= imagefontheight($size);                                                                                                                                                                                               
                  $error_string_x=$start_x;                                                                                                                                                                                               
               }                                                                                                                                                                                               
               imagestring( $im, $size, $error_string_x+1, $error_string_y+1, $c, $wc);                                                                                                                                                                                               
               imagestring( $im, $size, $error_string_x, $error_string_y, $c, $color);                                                                                                                                                                                               
                                                                                                                                                                                                              
               $error_string_x += imagefontwidth($size);                                                                                                                                                                                               
               if ($c=="]")                                                                                                                                                                                               
               {                                                                                                                                                                                               
                  $color=$col;                                                                                                                                                                                               
                  $error_string_y+= imagefontheight($size);                                                                                                                                                                                               
                  $error_string_x=$start_x;                                                                                                                                                                                               
               }                                                                                                                                                                                               
           }                                                                                                                                                                                               
           if ($error_string_x>=$limit-5)                                                                                                                                                                                                
           {                                                                                                                                                                                               
              $error_string_x=$start_x;                                                                                                                                                                                               
              $error_string_y+= 10;                                                                                                                                                                                               
           }                                                                                                                                                                                                
        }                                                                                                                                                                                                 
    }                                                                                                                                                                                               



function multipart_render ($nntp, $message, $saveas="",$fromfile=false,$limit=NULL,$font=NULL)                                                                                                                                                                                               
{                   
    global $breadcrumb;             
    $breadcrumb .= "Dm";                                                                                                                                                                                         
    $header  = $message->get_main_header();                                                                                                                                                                                                   
    $subject = $header["subject"];                                                                                                                                                                                                
                                                                                                                                                                                                   
    if ($fromfile)                                                                                                                                                                                               
    {                                                                                                                                                                                               
         print "Searching for " . $subject . " <br>";                                                                                                                                                                                               
    }                                                                                                                                                                                               
    // lookup file segments                                                                                                                                                                                               
    $multi_test = multipart_lookup ($subject, $nntp);                                                                                                                                                                                                
                                                                                                                                                                                                   
    $encode  = "";                                                                                                                                                                                               
    $count   = 0;                                                                                                                                                                                               
    $type    = parse_MIME_header ($subject);                                                                                                                                                                                               
                                                                                                                                                                                                    
                                                                                                                                                                                                    
    $fn_test = preg_match('/>*"*(\S+)\s*.(jpeg|jpg|gif|png|mpg|wmv|nzb|avi|rar)/i', $subject, $image_fn);                                                                                                                                                                                               
    if ($fn_test)                                                                                                                                                                                               
    {                                                                                                                                                                                               
        $out_file_name = $image_fn[0];                                                                                                                                                                                               
    }                                                                                                                                                                                               
    else                                                                                                                                                                                               
    {                                                                                                                                                                                               
        print APPLICATION_NAME . " cannot process these types of files." . $subject;                                                                                                                                                                                               
        exit;                                                                                                                                                                                               
    }                                                                                                                                                                                                
                                                                                                                                                                                                  
    if (isset($_GET["debug"]))                      
    {                      
        header("Content-Type: text/plain");                       
    }                                                                                                                                                                                                     
    $concatenated_content = "";                     
    $raw_yenc_data = array();                                                                                                                                                                                              
    $messages = array();                                                                                                                                                                          
    $errors = array();                                                                                                                                                                  
    $error = NULL;             
                                                                                                                                                            
    $finds  = array();                                                                                                                                                                
    $found = NULL;                                                                                                                                                                 
# if this is part of a prior error, stop here and render the error file                                                                                                                                                                        
# to save resources                                                                                                                                                                                        
    foreach ($multi_test["sorter"] as $sorter)                                                                                                                                                                                                
    {   $match = $multi_test["matches"][$sorter];                                                                                                                                                                             
        $errors[] = $match->nntp_message_id;                                                                                                                                                                 
        $error_cache_file = "data/temp/error/_" . $nntp->group_address . "_error_" . $match->nntp_message_id . ".txt";               
        $raw_cache_file   = cache_file ($match->nntp_message_id, "raw", $nntp->group_address);                                                                                                                                                                      
        if (file_exists($error_cache_file))                                                                                                                                                                                          
        { #...draw the image and stop here                                                                                                                                                                      
            $error = $match->nntp_message_id;                                                                                                                                            
        }            
        if (file_exists($raw_cache_file))                                                                                                                                                                                          
        { #...draw the image and stop here                                                                                                                                                                    
            $error = $match->nntp_message_id;                                                                                                                                                                     
            # decode_message_content_output(array(), $limit, $font, $match->nntp_message_id, $nntp->group_address);                
            # exit;                                                                                                                                        
        }                                                                                                                                                                                                                  
    }                   
                                                                                                                                                                      
    if ($error)                                                                                                                                                                 
    {                                                                                                                                                                 
        foreach ($errors as $pointer)                                                                                                                                                                 
        {                                                                                                                                                                 
            $error_point_file = "data/temp/error/_" . $nntp->group_address . "_error_" . $pointer . ".txt_pointer";                                                                                                                                                                   
            WriteToFile ($error_point_file, $error);                                                                                                                                                                                                  
        }                                                                                                                                                                                         
        $breadcrumb .= "[".$error_cache_file." - " . date("H:i:s",filemtime($error_cache_file)) . "]";                                                                                                                                                                   
        # echo "<xmp>" . $breadcrumb; print_r ($errors);                                                                                                                                                                                     
        decode_message_content_output(array(), $limit, $font, $error, $nntp->group_address);                                                                                                                                                                                          
        exit;                                                                                                                                                                  
    }                                                                                                                                                                 
# retrieve a sorted list of articles from the news-server                                                                                                                                                                                                               
    foreach ($multi_test["sorter"] as $sorter)                                                                                                                                                                                                
    {                                                                                                                                                                                                   
        $match = $multi_test["matches"][$sorter];                                                                                                                                                                   
        $response = $nntp->parse_response($nntp->send_request("article ".$match->nntp_message_id));                                                                                                                                                                                                
        if (($response["status"] == ARTICLE_BODY) || ($response["status"] == ARTICLE_HEAD_BODY)) {                                                                                                                                                                                                
            $message = "";                                                                                                                                                                                                
            $buf = fgets($nntp->nntp, 4096);                                                                                                                                                                                                
            while (!preg_match("/^\.\s*$/", $buf)) {                                                                                                                                                                                                
                $message .= $buf;                                                                                                                                                                                                
                $buf = fgets($nntp->nntp, 4096);                                                                                                                                                                                                
            }                                                                                                                                                                                                
        }                                                                                                                                                                      
                                                                                                                                                                                              
        $messages[] = array("match_id"=>$match->nntp_message_id,"message"=>$message,"group"=>$nntp->group_address);                                                                                                                                                                                               
    }                                                                                                                                                                                               
                                                                                                                                                                                                   
    #print_r ($messages);                                                                                                                                                                                               
    #exit;                                                                                                                                                                                               
                                                                                                                                                                                                   
    $match_id=NULL;                                                                                                                                                                                               
    $group_id=NULL;                                                                                                                                                                                               
    foreach ($messages as $m)                                                                                                                                                                                                
    {                                                                                                                                                                                                   
        $match_id   = $m["match_id"];                                                                                                                                                                                                   
        $group_id   = $m["group"];                                                                                                                                                                                                   
        $message    = $m["message"];                                                                                                                                                                                                                                   
        if ($saveas=="")                                                                                                                                                                                               
        {                                                                                                                                                                                               
                                                                                                                                                                                                       
            $result = new MIME_Message($message);                                                                                                                                                                                                            
            $parts  = $result->get_total_part();                                                                                                                                                                                               
            $body   = $result->get_part_body($parts-1);                                                                                                                                                                                               
            $header = $result->get_part_header($parts-1);                                                                                                                                                                                               

            if (isset($_GET["debug"]))                      
            {                      
                echo "<xmp>$body</xmp>";                      
            }                                  
                                                                                                                                                                                                 
            if ($count==0)                                                                                                                                                                                               
            {                                                                                                                                                                                                
                if (preg_match("/^begin\s+[0-9][0-9][0-9]\s+(.+?)\s*\r?\n/m", $body, $temp))                                                                                                                                                                                                
                {                                                                                                                                                                                               
                    $encode  = "uuencode";                                                                                                                                                                                            
                }                                                                                                                                                                                               
                else if ( (strpos($body, "ybegin") !== false) || (strpos(strtolower($subject), "yenc") !== false) )                                                                                                                                                                                               
                { // YENC decoding do nothing                                                                                                                                                                                               
                    $encode  = "yenc";                                                                                                                                                                                                
                }                                                                                                                                                                                                 
            }                           
            $raw_yenc_data[] = $body;                                                                                                                                                                                           
            $concatenated_content .= trim($body) . "\r\n";                                                                                                                                                                                                
        }                                                                                                                                                                                                
        else                                                                                                                                                                                               
        {                                                                                                                                                                                               
            print "Saving " . "multipart_" . $match_id . ".txt<br>\n";                                                                                                                                                                                               
            WriteToFile ("multipart_" . $match_id . ".txt", $message);                                                                                                                                                                                               
        }                                                                                                                                                                                               
        $count ++;                                                                                                                                                                                                 
    }                                                                                                                                                                                               
                                                                                                                                                                                                   
    if ($saveas!="")                                                                                                                                                                                               
    {                                                                                                                                                                                               
        return $multi_test;                                                                                                                                                                                               
    }                                                                                                                                                                                               
                                                                                                                                                                                                
    $nntp->quit();                                                                                                                                                                                                
    #exit;                                                                                                                                                                                               
    if (isset($_GET["debug"]))                      
    {                      
        exit;                      
    }                                  
                                                                                                                                                                                                              
    if (preg_match("/^begin\s+[0-9][0-9][0-9]\s+(.+?)\s*\r?\n/m", $concatenated_content)) {                                                                                                                                                                                                
        $parts = preg_match("/^begin\s+[0-9][0-9][0-9]\s+(.+?)\s*\r?\n(.*?)end/ms", $concatenated_content, $tmp);                                                                                                                                                                                               
        if ($parts)                                                                                                                                                                                               
        {                        
           $name = $tmp[1];                                                                                                                                                                                           
           $concatenated_content = $tmp[2];                                                                                                                                                                                               
        }                                                                                                                                                                                                 
    }                                                                                                                                                                                               
    else if (preg_match("/^=ybegin.*name=([^\\r\\n]+)/im", $concatenated_content, $tmp))                
    {                
                              
        $name = trim($tmp[1]);                
    }                                                                                                                                                                                               
                                      
                                                                                                                                                                                                    
    #header("Content-Type: text/plain");                                                                                                                                                                                               
    #print $concatenated_content;                                                                                                                                                                                               
                                                                                                                                                                                                   
                                                                                                                                                                                                   
                                                                                                                                                                                                    
                                                                                                                                                                                                   
    $arr = array ();                                                                                                                                                                                               
    $arr["header"]     = array ("content-type"=>$type, "content-transfer-encoding" => $encode);                                                                                                                                                                                               
    $arr["body"]       = $encode=="yenc" ? $raw_yenc_data : $concatenated_content;                   
    $arr["filename"]   = $name;                                                                                                                                                                                             
    #$arr["count"]      = $count;                                                                                                                                                                                               
                                                                                                                                                                                                   
                                                                                                                                                                                                    
    if ($saveas=="")                                                                                                                                                                                               
    {                                                                                                                                                                                               
        decode_message_content_output($arr,$limit,$font,$match_id,$group_id,$errors);                                                                                                                                                                                               
    }                                                                                                                                                                                               
    else                                                                                                                                                                                               
    {                                                                                                                                                                                                 
        $binary = decode_message_content($arr);                                                                                                                                                                                               
        WriteToFile ($saveas, $binary);                                                                                                                                                                                                
        print "File saved as <a href='".$saveas."'>".$saveas."</a>";                                                                                                                                                                                               
    }                                                                                                                                                                                               
                                                                                                                                                                                                   
    exit(0);                                                                                                                                                                                               
                                                                                                                                                                                                       
}                                                                 
function group_lookup ($userx, $passx, $group, $def="")                                                                                                                                                                                               
{                                                                                                                                                                                               
    global $nntp_server,$user,$pass;                                                                                                                                                                                               
    global $breadcrumb;                                                                                                                                                                                               
    $servers = array(                                                                                                                                                                                               
            array("news-east.usenet.com","1053900012","cyber8"),                                                                                                                                                                                                
            array("news-west.usenet.com","1053900012","cyber8"),                                                                                                                                                                                               
            array("multimedia-west.usenet.com","1053900012","cyber8"),                                                                                                                                                                                               
            array("multimedia-east.usenet.com","1053900012","cyber8"),                                                                                                                                                                                               
            array("images-west.usenet.com","1053900012","cyber8"),                                                                                                                                                                                               
            array("images-east.usenet.com","1053900012","cyber8"),                                                                                                                                                                                               
            array("mp3-east.usenet.com","1053900012","cyber8"),                                                                                                                                                                                               
            array("mp3-west.usenet.com","1053900012","cyber8")                                                                                                                                                                                                
        );                                                                                                                                                                                               
    $connected = false;                                                                                                 
    $folders = get_profile_value("", "servers");                                                                                                                                                                                          
    if ($def=="")                                                                                                                                                                                               
    { # look up server from PROFILE                                                                                                                                                                                               
                                                                                                                                                           
        if (strlen($folders)>0)                                                                                                                                              
        {                                                                                                                                                                                      
            parse_str( $folders );                                                                                                                                                                                               
            $servers = array();                                                                                                                                                                                               
            $ds=get_profile_value ($host, "defaultserver");                                                                                                                                                                                                
            if ($ds!="")                                                                                                                                                                                               
            {                                                                                                                                                                                               
                $servers[] = explode ("\t",$sg_s[$ds]);                                                                                                                                                                                 
              #  $breadcrumb .= "\n [" . $sg_s[$ds] . "] \n";                                                                                                                                                                                                                                                    
            }                                                                                                                                                                                               
            while (list($a,$b)=each($sg_s))                                                                                                                                                                                               
            {                                                                                                                                                                                               
                $servers[] = explode ("\t",$b);                                                                                                                                                                               
              #  $breadcrumb .= "\n (" . $b . ") \n";                                                                                                                                                                                             
            }                                                                                                                                                 
        }                                                                                                                                                                                               
    }                                                                                                                                                                                               
    else                                                                                                                                                                                               
    {                                                                                                                                                       
        if (strlen($folders)>0)                                                                                                                                              
        {                                                                                                                                                                                      
            parse_str( $folders );                                                                                                                                                                                               
            $servers = array();                                                                                                                                                            
            $servers[] = explode ("\t",$sg_s[$def]);                                                                                                                                                                                 
          #  $breadcrumb .= "\n [" . $sg_s[$def] . "] \n";                                                                                                                                                                                                                                                                                      
        }                                                                                                                                                                                                                         
    }                                                                                                                                                                                                   
                                                                                                                                                                                  
    foreach ($servers as $server_arr)                                                                                                                                                                                               
    {                                                                                                                                                                                               
        $server = $server_arr[0];                                                                                                                                                                                               
        $user   = $server_arr[1];                                                                                                                                                                                               
        $pass   = $server_arr[2];                                                                                                                                                                                               
        $nntp   = new NNTP($server, $user, $pass);                                                                                                                                                                                                                                              
        if ($nntp->connect())                                                                                                                                                                                                
        {                                                                                                                                                                                                
            $group_info = $nntp->join_group($group);                                                                                                                                                                                                                                             
            if ($group_info != NULL)                                                                                                                                                                                                
            {                                                                                                                                                                                                
                $nntp_server = $server;                                                                                                                                                                                               
                $breadcrumb .= "CONNECTED TO $server AND JOINED $group\n";                             
                $connected   = true;                                                                                                                                                
                break;                                                                                                                                                                                               
            }                                                                                                   
            else                                                                                            
            {                                                                                            
                $breadcrumb .= "FAILED TO JOIN TO $group ON $server\n";                                                                                             
            }                                                                                                                                                                                                    
        }                                                                                                  
        else                                                                                            
        {                                                                                            
            $breadcrumb .= implode("\n", $server_arr) . "FAILED TO CONNECT TO $server\n";                                                                                             
        }                                                                                                                                                                                                                                
    }                             
    if (!$connected) return false;                                                                                                                                                                                          
    return $nntp;                                                                                                                                                                                               
}                                                                                                                                                                                                    
                                                                                                                                                                                        
                                                                                                                                                                              
function rounded_mask ($target,$width="",$height="")                                                                                                                                                                                                 
{                                                                                                                                                             
    $nntp_server="NewsJet";                                                                                                                                              
     if ($width=="") $width=imagesx($target);                                                                                                                                              
     if ($height=="") $height=imagesy($target);                                                                                                                                              
     $curve=12;                                                                                                                                                    
                                                                                                                                                                 
    $radius = $curve * 2;                                                                                                                                                                                                 
    $right  = $width - $curve;                                                                                                                                                                                                 
    $bottom = $height - $curve;                                                                                                                                                                                                 
                                                                                                                                                                                                     
    $im = imagecreate($width,$height);                                                                                                                                                         
                                                                                                                                                 
    $az = imagecolorallocate ($im,255,255,255);                                                                                                                                              
    $cg = imagecolorallocate ($im,255,99,255);   // palette color ( transparent )                                                                                                                                                                                                 
    if ($active=="")                                                                                                                                                                                                 
    {                                                                                                                                                                                                 
        $wg = imagecolorallocate ($im,255,255,255); // background color                                                                                                                                                                                                 
        $bg = imagecolorallocate ($im,100,100,100); // border color                                                                                                                                                                                                 
    }                                                                                                                                                                                                 
    else                                                                                                                                                                                                 
    {                                                                                                                                                                                                 
        $wg = imagecolorallocate ($im,245,245,245); // background color                                                                                                                                                                                                 
        $bg = imagecolorallocate ($im,166,166,166); // border color                                                                                                                                                                                                 
    }                                                                                                                                                                                                 
                                                                                                                                                                   
    $zz = imagecolorallocate ($im,0,0,0);                                                                                                                                                   
    $bg=$zz;                                                                                                                                                                        
    imagecolortransparent ($im, $cg);                                                                                                                                                                                                 
    $wg=$cg;                                                                                                                                                     
                                                                                                                                                                                               
                                                                                                                                                   
                                                                                                                                                                                                     
    imagefilledellipse ($im,$curve,$curve,$radius,$radius,$wg);        /* NW curve */                                                                                                                                                                                                   
    imagefilledellipse ($im,$right-1,$curve,$radius,$radius,$wg);      /* NE curve */                                                                                                                                                                                                    
    imagefilledellipse ($im,$right-1,$bottom-1,$radius,$radius,$zz);   /* SE curve */                                                                                                                                                                                                      
    imagefilledellipse ($im,$curve,$bottom-1,$radius,$radius,$zz);     /* SW curve */                                                                                                                                                                                                
                                                                                                                                                                                                     
    imageellipse ($im,$curve,$curve,$radius,$radius,$bg);              /* NW curve border */                                                                                                                                                                                  
    imageellipse ($im,$right-1,$curve,$radius,$radius,$bg);            /* NE curve border */                                                                                                                                                                                                    
    imageellipse ($im,$right-1,$bottom-1,$radius,$radius,$bg);         /* SE curve border */                                                                                                                                                                                              
    imageellipse ($im,$curve,$bottom-1,$radius,$radius,$bg);           /* SW curve border */                                                                                                                                                                                                  
                                                                                                                                                                                                     
    imagefilledrectangle ($im, $curve,0,$right,$height,$wg);           /* vertical cover */                                                                                                                                                                                      
    imagefilledrectangle ($im, 0,$curve,$width,$bottom,$wg);           /* horizontal cover */                                                                                                                                                                                                
                                                                                                                                                                                                                                
    imagefilledrectangle ($im, $curve,$bottom+1,$right,$height,$zz);   /* caption cover */                                                                                                                                                         
    imagestring($im,1,1+$curve,$bottom+3,$nntp_server,$bg);            /* caption text shadow */                                                                                                                                                          
    imagestring($im,1,$curve,$bottom+2,$nntp_server,$wg);              /* caption text */                                                                                                                                                     
                                                                                                                                                             
    imageline ($im,$curve,0,$right,0,$bg);                                                                                                                                                                                                 
    imageline ($im,0,$curve,0,$bottom,$bg);                                                                                                                                                                                                  
                                                                                                                                                                                                     
    imageline ($im,$curve,$height-1,$right,$height-1,$bg);                                                                                                                                                                                                 
    imageline ($im,$width-1,$curve,$width-1,$bottom,$bg);                                                                                                                                                      
                                                                                                                                                  
    imagecopy ($target,$im,0,0,0,0,$width,$height);                                                                                                                                                  
                                                                                                                                                  
    return $target;                                                                                                                                                                                                 
}                           

?>